#ifndef __PLATFORM_LIB_BASE64_H__
#define __PLATFORM_LIB_BASE64_H__
#ifdef __cplusplus
extern "C"
{
#endif

#include "pf_common.h"

/******************************************************************************************************/

enum PF_BASE64_CALC_TYPE
{
    PF_BASE64_ENCODE    = 1,
    PF_BASE64_DECODE    = 2,
};

/*********************************************************************************************
Function Name:  pf_base64_encode
Description  :  Encode original data to base64 string
Inputs       :  const void*      input       : the original string to handle
                int32_t          input_size  : the len of the input string
                char*            output      : the buffer to recode the encoded string
                int32_t          output_size : the len of the buffer
                const char*      last_2      : the last2 string
                                               the word should be different two word.
                                               each between '! ' and '~'
                                               except a~z A~Z 0~9 and '='
Outputs      :  int32_t                      : 0 for ok
                                               PF_EINVAL for error
ErrorCodes   :  PF_EINVAL                    : if output_size too few
                                               (must larger than (input_size * 4 / 3))
                                               or the last_2 error
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
huyq                   2011-06-23                    create
**********************************************************************************************/
extern int32_t pf_base64_encode(const void* input,
                                int32_t input_size,
                                char* output,
                                int32_t output_size,
                                const char* last_2);

/*********************************************************************************************
Function Name:  decode base64 string to original data
Description  :  Encode original data to base64 string
Inputs       :  const          char* input  : the encoded string
                int32_t         input_size  : the len of the the encoded string
                void*               output  : the buffer to recode the decoded string
                int32_t        output_size  : the len of the buffer
                const char*         last_2  : the last2 string
                                              the word should be different two word.
                                              each between '! ' and '~'
                                              except a~z A~Z 0~9 and '='
Outputs      :  int32_t                     : 0 for ok
                                            : PF_EINVAL for error
ErrorCodes   :  PF_EINVAL                   : if output_size too few
                                              (must larger than (input_size * 3 / 4))
                                              or the last_2 error
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
huyq                   2011-06-23                    create
**********************************************************************************************/
extern int32_t pf_base64_decode(const char* input,
                                int32_t input_size,
                                void* output,
                                int32_t output_size,
                                const char* last_2);

/*********************************************************************************************
Function Name:  pf_base64_get_len
Description  :  Get the len of output after decode or encode
Inputs       :  int32_t input_len              : the length of the original string
                enum PF_BASE64_CALC_TYPE type  : the type of the original string
                                                 1 : for the original string should be encode
                                                 2 : for the original string should be decode
Outputs      :  int32_t                        : the len of output after decode or encode
                                                 not include the len of '\0'
                                                 PF_EINVAL for error
ErrorCodes   :  PF_EINVAL                      : the type not define(1,2), or the len of 
                                                 original string which the type is 2 mod 4 
                                                 not equals 0
History      :
---------------------------------------------------------------------------------------------
Author                 Date                          Comments
huyq                   2011-06-23                    create
**********************************************************************************************/
extern int32_t pf_base64_get_len(int32_t input_len, enum PF_BASE64_CALC_TYPE type);

/******************************************************************************************************/

#ifdef __cplusplus
}
#endif
#endif /* #ifndef __PLATFORM_LIB_BASE64_H__ */


